<!-- components/EditForm.vue -->
<template>
  <el-dialog v-model="visible" title="编辑标签">
    <el-form :model="formData">
      <el-form-item label="名称">
        <el-input v-model="formData.name" />
      </el-form-item>
      <el-form-item label="中文名称">
        <el-input v-model="formData.cn_name" />
      </el-form-item>
      <el-form-item label="标签">
        <el-input v-model="formData.des" type="textarea" resize="none" :autosize="{ minRows: 2, maxRows: 8 }"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleSubmit">提交</el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'

const visible = ref(false)
const formData = reactive({
  id: '',
  name: '',
  cn_name: '',
  des: ''
})

const emit = defineEmits(['submit'])

const open = (data: any) => {
  Object.assign(formData, data)
  visible.value = true
}

const handleSubmit = () => {
  emit('submit', { ...formData })
  visible.value = false
}

defineExpose({ open })
</script>
